/*
 * Created by SharpDevelop.
 * User: tjog
 * Date: 10/22/2009
 * Time: 2:46 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Data;
using System.Windows.Forms;
using System.Drawing;
using System.Text;
using System.Collections.Generic;
using WeifenLuo.WinFormsUI.Docking;

namespace test
{
	
	//
	// From MSDN
	// -------------------------------------------------------------------------------------------
	// Notes to Inheritors When you derive from DataGridViewColumnHeaderCell and add 
	// new properties to the derived class, be sure to override the Clone method to 
	// copy the new properties during cloning operations. You should also call the base
	// class's Clone method so that the properties of the base class are copied to the new cell.
	//
	public class DecDataGridViewColumnHeaderCell : DataGridViewColumnHeaderCell 
	{
		protected override void OnMouseClick(DataGridViewCellMouseEventArgs e) 
		{
			if(base.DataGridView != null)
			{
				base.OnMouseClick(e);
			}
		}
				public override Object Clone() {
			return base.Clone();
		}
	}
	/// <summary>
	/// Description of DecDataGridView.
	/// </summary>
	public class DecDataGridView : DataGridView
	{
		public DecDataGridView()
		{
			this.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
		}
		protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e) {
			int rowNum = e.RowIndex + 1;
			string rowNumStr = rowNum.ToString();
			
			SizeF size = e.Graphics.MeasureString( rowNumStr, this.Font);
			
			int slack = 20;
			if(this.RowHeadersWidth < (int) (size.Width + slack))
				this.RowHeadersWidth = (int) (size.Width + slack);
			
			Brush b = SystemBrushes.ControlText;
			
			StringFormat format = new StringFormat(StringFormatFlags.NoClip);
			//format.Alignment = StringAlignment.Near;
			
			e.Graphics.DrawString( rowNumStr, this.Font, b, e.RowBounds.Location.X + 15,
			                      e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2), format);
	
			
			base.OnRowPostPaint(e);
		}
		
	}
	
	public class DecDataGridDockContent : DockContent {
		public DecDataGridDockContent() {
			this.gridView = new DecDataGridView();
			this.gridView.AllowUserToOrderColumns = true;
			this.gridView.AllowUserToAddRows = false;
			this.gridView.ReadOnly = true;
			this.gridView.Dock = DockStyle.Fill;
			// Need this line as funnily the gridView member is not instantiated until this call
			this.Controls.Add(this.gridView);
		}
		public DecDataGridView gridView;
	}
}
